<template>
	<view>
		<view class="all">
			<view class="text-title">
				欢迎登录我爱我房
			</view>
			<view>
				<u-form :model="form" ref="uForm">
					<u-form-item style="margin-bottom: 42rpx;" label="" label-position="top">
						<u-input v-model="form.numPhone" placeholder="请输入手机号码"/>
						<view slot="right" class="code">获取验证码</view>
					</u-form-item>
					<u-form-item label="" label-position="top">
						<u-input v-model="form.code"  placeholder="请输入验证码"/>
					</u-form-item>
				</u-form>
				<view class="phone-logo">
					登陆
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// txtFlag: false,
				form:{
					numPhone:'',
					code:'',
				}
			}
		},
		onShow() {
			this.txtFlag = uni.getStorageSync('changePhone');
		},
		methods: {
			// 获取手机号
			getphonenumber(e) {
				let _this = this;
				console.log(e.detail)
				if (e.detail.encryptedData) {

					// 获取解密手机号
					_this.$request.api.phone({
						sessionKey: uni.getStorageSync('sessionKey'),
						openId: uni.getStorageSync('openId'),
						date: e.detail.encryptedData,
						iv: e.detail.iv,
					}).then(res => {
						// 存手机号
						uni.setStorageSync('phone', res.data.data.data.phone);
						// 若是修改过的直接进入实名认证
						if (uni.getStorageSync('changePhone')) {
							_this.$request.api.name({
								name: uni.getStorageSync('name'),
								id_card: uni.getStorageSync('id'),
								phone: res.data.data.data.phone,
								open_id: uni.getStorageSync('openId'),
							}).then(res => {
								// 1.没手机号
								// 2.两手几号不一样
								// 3.新用户
								console.log(res.data.data)
								if (res.data.data.data.sign == 1) {
									uni.setStorageSync('loginFlag', true),
										uni.setStorageSync('changePhone', false),
										_this.$Router.push({
											path: '/my/address/address'
										})
								} else if (res.data.data.data.sign == 2) {
									uni.showModal({
										content: '当前手机号与助业账户不符\n请切换为: ' + res.data.data.data.phone,
										showCancel: false,
										confirmText: '确认',
										confirmColor: '#F9A832',
										success: function(res) {

										}
									});
								}

							})

						} else {
							if (res.data.data.data.sign == 1) {
								// 进入实名认证页面
								_this.$Router.push({
									path: '/homePage1/realName/realName'
								})
							} else {
								uni.setStorageSync('loginFlag', true),
									// 进入首页
									_this.$Router.pushTab({
										path: '/pages/index/index'
									})
							}

						}
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.all {
		width: 100vw;
		height: 100vh;
		padding: 80rpx 48rpx 160rpx 48rpx;

		.text-title {
			font-size: 32rpx;
			font-weight: 500;
			color: #333333;
			margin-bottom: 160rpx;
		}
		.code{
			font-size: 24rpx;
			font-weight: 500;
			color: #666666;
		}
		.phone-logo{
			height: 100rpx;
			background: #F9A832;
			border-radius: 50rpx;
			font-size: 32rpx;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 100rpx;
			margin-top: 120rpx;
		}
	}

	.phone-wrap {
		width: 100vw;
		height: 100vh;

		.login-head {
			height: 200rpx;
		}

		.weixin-login {
			width: 614rpx;
			height: 100rpx;
			border-radius: 50rpx;
			background: #F9A832;
			box-shadow: 0px 4px 10px 0px rgba(249, 168, 50, 0.3);
			margin-top: 120rpx;
			line-height: 100rpx;
			color: #fff;
		}

	}
</style>
